package nl.scalasim
package cli

import nl.scalasim.actors._
import nl.scalasim.actors.traits.SimulationActor

/**
 * Setting for iteration 1. 
 *
 * @author Yigal Duppen
 * @since Oct 1, 2010
 */
class Example1Setting extends Setting {

  val citizen = ActorDescriptor(
    "Citizen",
    "Citizens do all the work in your beautiful city",
    canBuild = false,
    mnemonic = '@')

  val mountain = ActorDescriptor(
    "Mountain",
    "Mountains are impassable terrain that provide Stone",
    canBuild = false,
    mnemonic = '^')

  val quarry = ActorDescriptor(
    "Quarry",
    "Quarries delve stone from nearby mountains",
    mnemonic = 'Q',
    width = 2, depth = 2)

  val wheatFarm = ActorDescriptor(
    "Wheat farm",
    "Wheat farms harvest wheat from adjacent wheat fields",
    mnemonic = 'W',
    width = 2, depth = 2)

  val riceFarm = ActorDescriptor(
    "Rice farm",
    "Rice farms harvest rice from adjacent rice fields",
    mnemonic = 'R',
    width = 2, depth = 2)

  val house = ActorDescriptor(
    "House",
    "Build houses to attract new citizens",
    mnemonic = 'H',
    width = 3, depth = 3)

  val wheatField = ActorDescriptor(
    "Wheat field",
    "Wheat fields grow wheat; build a wheat farm nearby to harvest it",
    mnemonic = 'w',
    width = 4, depth = 4
    )

  val riceField = ActorDescriptor(
    "Rice field",
    "Rice fields grow rice; build a rice farm nearby to harvest it",
    mnemonic = 'r',
    width = 4, depth = 4
    )

  val granary = ActorDescriptor(
    "Granary",
    "Granaries provide unlimited storage form rice and wheat",
    mnemonic = 'G',
    width = 2, depth = 2
    )

  /*
 def types = Set(
   ActorDescriptor("Bakery", "Bakeries convert wheat into bread", true),
   ActorDescriptor("Market", "Sells rice and bread to citizens, providing money as a result", true),
   ActorDescriptor("Theater", "Provides happiness to all housing within its radius", true)
 )
  */


  private val descriptors = collection.immutable.Map[ActorDescriptor, AddressBook => SimulationActor](
    citizen -> {
      a =>
        new Citizen(a, citizen, 10, 12, 3)
    },
    mountain -> {
      a =>
        new InfiniteProducer(
          addressBook = a,
          descriptor = mountain,
          goods = "stone",
          speed = 4
          )
    },
    riceField -> {
      a =>
        new InfiniteProducer(
          addressBook = a,
          descriptor = riceField,
          goods = "rice",
          speed = 4
          )
    },
    wheatField -> {
      a =>
        new InfiniteProducer(
          addressBook = a,
          descriptor = wheatField,
          goods = "wheat",
          speed = 4
          )
    },
    quarry -> {
      a =>
        new SimpleHarvester(
          addressBook = a,
          descriptor = quarry,
          goods = "stone",
          speed = 4,
          capacity = 20,
          maxWorkers = 1
          )
    },
    wheatFarm -> {
      a =>
        new Farm(
          addressBook = a,
          descriptor = wheatFarm,
          goods = "wheat",
          speed = 4,
          capacity = 6,
          maxResidents = 1
          )
    },
    riceFarm -> {
      a =>
        new Farm(
          addressBook = a,
          descriptor = riceFarm,
          goods = "rice",
          speed = 4,
          capacity = 6,
          maxResidents = 1
          )
    },
    house -> {
      a =>
        new House(
          addressBook = a,
          descriptor = house,
          maxResidents = 4
          )
    },
    granary -> {
      a =>
        new Warehouse(
          addressBook = a,
          descriptor = granary,
          capacity = collection.immutable.Map("wheat" -> 1000, "rice" -> 1000),
          totalCapacity = 2000
          )
    }

    )


  def types = descriptors.keySet.toSet

  def newActor(d: ActorDescriptor, a: AddressBook): Option[SimulationActor] = {
    descriptors.get(d) match {
      case None => None
      case Some(f) => Some(f(a))
    }
  }
}